package cn.chenxiejia;

import java.io.*;

/***
 * @program: maven
 * @ClassName: File7
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/1/18 20:35
 * @version : V1.0
 */
public class File7 {
    public static void main(String[] args) throws FileNotFoundException {
        File file = new File("E:/aa.txt");
        File file1 = new File("D:/aa.txt");


        try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
            int len = 0;
            int i = 1;
            byte[] buf = new byte[(int) (file.length() / 17)];
            while ((len = raf.read(buf)) != -1) {
                //随机访问文件流rw阅读和修改
                RandomAccessFile raf1 = new RandomAccessFile(new File("D:/aa" + i + ".txt"), "rw");
                raf.seek((file.length() / 17) * i);

                raf1.write(buf);
                ++i;
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        int j = 0;
        FileOutputStream fos = new FileOutputStream(file1, true);
//        int num = 0;
//        if (file.length() % a != 0) {
//            num = (int) ((file.length() % a) + 1);
//        }
        for (int i = 1; i <= 17; i++) {
            ++j;
            try (FileInputStream fis = new FileInputStream(new File("D:/aa" + j + ".txt"))) {
                fos.write(fis.readAllBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
